package com.dingwen.stu.spr.ann;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;

/**
 * 基于注解实现切面
 *
 * @author dingwen
 * @date 2021/10/07
 */
@Aspect
//@EnableAspectJAutoProxy
public class AnnotationPointCut {
    @Before("execution(* com.dingwen.stu.spr.aop.*.*(..))")
    public void before(){
        System.out.println("自定义注解实现，方法之前之前通知执行");
    }

    @After("execution(* com.dingwen.stu.spr.aop.*.*(..))")
    public void after(){
        System.out.println("自定义注解实现，方法执行之后执行");
    }
    @Around("execution(* com.dingwen.stu.spr.aop.*.*(..))")
    public void around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println("自定义注解实现，环绕通知执行");

        // 获取方法签名
        Signature signature = proceedingJoinPoint.getSignature();
        // 方法执行
        proceedingJoinPoint.proceed();
        System.out.println("自定义注解实现，环绕通知执行");

    }
}
